$(function () {
    let flag = true;
    let isHaveMoney = true; //确认金额
    let timer = 3;          //防止用户多次点击
    let money = "10";
    let userNumbers = "";
    $("#confirm").on("click", function () {
        alert("手机号不存在")
    })
    // 选择购买钻石事件
    $('.chooseMoney').on('click', 'li', function () {
        $('.chooseMoney li').removeClass("liactive")
        $(this).addClass('liactive');
        isHaveMoney = true;
        money = $(this).context.children[1].innerText
        var basic = money;
        basic = basic.substr(0, basic.length - 1);
        money = basic;
        $("#otherAmount")[0].value = "";
        $("#otherNum")[0].innerText = "";
    });
    // 其他金额
    $("#otherAmount").on("click", function () {
        $('.chooseMoney li').removeClass("liactive");
        isHaveMoney = false;
    })
    $("#otherNum").text(this.value);
    // 输入
    $("#otherAmount").on("input", function () {
        $("#otherNum").text(this.value);
        if (this.value >= 3000) {
            this.value = 3000
            money = this.value;
            $("#otherNum").text(3000);
        } else if (this.value >= 0) {
            isHaveMoney = true;
            money = this.value;
        } else {
            this.value = "";
            $("#otherNum").text("");
            isHaveMoney = false;
            money = this.value;
        }
    })
    // 支付事件
    function send() {
        alert("账号不存在")
        if (!flag) {
            alert("请确认协议")
        }
        if (flag && !isHaveMoney) {
            alert("请确认金额")
        }
        if (isHaveMoney && flag) {
            console.log("支付成功")
            console.log(money)
            userNumbers = $("#userNumber")[0].value
            console.log(userNumbers)
        }
        $("#paymentBtn").unbind("click");
        let start = setInterval(function () {
            $("#paymentBtn").on('click', send)
            clearInterval(start)
        }, timer * 1000)
    }
    // 支付按钮
    $("#paymentBtn").on('click', send)
    // 协议
    function change() {
        if (flag) {
            $("#agree").css("background-image", "url(../imgs/勾.png)")
        } else {
            $("#agree").css("background-image", "none")
        }
    }
    change();
    // 同意协议
    $("#agree").on('click', function () {
        flag = !flag;
        change();
    })

})